#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include "mypushbutton.h"
#include <QDebug>
#include <QTimer>
#include <QSound>


MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 配置主场景
    // 设置窗口大小
    setFixedSize(320, 588);

    // 设置图标
    setWindowIcon(QIcon(":/res/Coin0001.png"));

    // 设置标题
    setWindowTitle("翻金币主场景");

    // 实现退出功能
    connect(ui->actiontuichu, &QAction::triggered, [=](){
        this->close();
    });

    // 准备开始按钮的音效
    QSound * startSound = new QSound(":/res/TapButtonSound.wav", this);

    // 开始按钮
    MyPushButton * startButton = new MyPushButton(":/res/MenuSceneStartButton.png");
    startButton->setParent(this);
    startButton->move(this->width() * 0.5 - startButton->width() * 0.5, this->height() * 0.7);

    // 实例化关卡场景
    chooseScene = new ChooseLeveScenne;

    // 监听选择关卡的返回信号
    connect(chooseScene, &ChooseLeveScenne::chooseSceneBack, this, [=](){
        chooseScene->hide();
        this->show();
    });

    connect(startButton, &QPushButton::clicked, [=](){
        // 播放开始音效
        startSound->play();

        // 弹跳特效
        startButton->zoom1();
        startButton->zoom2();

        // 延时进入到选择关卡场景
        QTimer::singleShot(500, this, [=](){
            this->hide();
            chooseScene->show();
        });

    });
}


// 重写paintEvent，设置背景图片
void MainWindow::paintEvent(QPaintEvent *)
{
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);

    // 画图标
    pix.load(":/res/Title.png");
    pix = pix.scaled(pix.width()*0.5, pix.height()*0.5);  // 缩放
    painter.drawPixmap(10,30,pix);
}

MainWindow::~MainWindow()
{
    delete ui;
}






















